//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.aidong.web.controller.sys;

import com.aidong.web.controller.BaseController;

import java.util.ArrayList;
import java.util.Iterator;
import javax.annotation.Resource;

import net.sf.ehcache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping({"cache"})
public class ClearCacheController extends BaseController {
    @Resource
    CacheManager cacheManager;

    public ClearCacheController() {
    }

    @RequestMapping({"list"})
    public ModelAndView list() {
        return (new ModelAndView("sys/cache/list")).addObject("cacheType", this.cacheManager.getCacheNames());
    }

    @RequestMapping({"_list"})
    public ModelAndView _list(@RequestParam("type") String type) {
        Cache cache = (Cache) this.cacheManager.getCache(type);
        ArrayList list = new ArrayList();
        if (cache != null) {
            Iterator mv = cache.getKeys().iterator();

            while (mv.hasNext()) {
                Object key = mv.next();
                list.add(cache.get(key));
            }
        }

        ModelAndView mv1 = new ModelAndView("sys/cache/_list");
        mv1.addObject("type", type);
        mv1.addObject("list", list);
        return mv1;
    }

    @RequestMapping({"_del"})
    @ResponseBody
    public String _del(@RequestParam("type") String type, @RequestParam("key") String key) {
        Cache cache = (Cache) this.cacheManager.getCache(type);
        if (cache == null) {
            return this.getResult(false, "没有这个缓存");
        } else {
            cache.remove(key);
            return this.getResult(true, "清除成功");
        }
    }
}
